<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="需求类别" prop="resultCategory">
        <el-select v-model="queryParams.resultCategory" placeholder="请选择" clearable>
          <el-option
            v-for="dict in dict.type.cxcy_result_category"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="技术领域" prop="technology">-->
<!--        <el-input-->
<!--          v-model="queryParams.technology"-->
<!--          placeholder="请输入技术领域"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="需求人姓名" prop="firstName">-->
<!--        <el-input-->
<!--          v-model="queryParams.firstName"-->
<!--          placeholder="请输入需求人姓名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="需求人ID" prop="firstId">-->
<!--        <el-input-->
<!--          v-model="queryParams.firstId"-->
<!--          placeholder="请输入需求人ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="负责人联系电话" prop="firstPhone">-->
<!--        <el-input-->
<!--          v-model="queryParams.firstPhone"-->
<!--          placeholder="请输入负责人联系电话"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="负责人身份证号" prop="firstIdnumber">-->
<!--        <el-input-->
<!--          v-model="queryParams.firstIdnumber"-->
<!--          placeholder="请输入负责人身份证号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="企业名称" prop="enterpriseName">
        <el-input
          v-model="queryParams.enterpriseName"
          placeholder="请输入企业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="统一社会信用代码" prop="enterpriseNumber">-->
<!--        <el-input-->
<!--          v-model="queryParams.enterpriseNumber"-->
<!--          placeholder="请输入统一社会信用代码"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="法人姓名" prop="corporateName">-->
<!--        <el-input-->
<!--          v-model="queryParams.corporateName"-->
<!--          placeholder="请输入法人姓名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="法人邮箱" prop="corporateEmail">-->
<!--        <el-input-->
<!--          v-model="queryParams.corporateEmail"-->
<!--          placeholder="请输入法人邮箱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="法人电话" prop="corporatePhone">-->
<!--        <el-input-->
<!--          v-model="queryParams.corporatePhone"-->
<!--          placeholder="请输入法人电话"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="法人身份证号" prop="corporateNumber">-->
<!--        <el-input-->
<!--          v-model="queryParams.corporateNumber"-->
<!--          placeholder="请输入法人身份证号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="企业营业执照" prop="businessLicense">-->
<!--        <el-input-->
<!--          v-model="queryParams.businessLicense"-->
<!--          placeholder="请输入企业营业执照"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="营业执照注册地" prop="licenseAddress">-->
<!--        <el-input-->
<!--          v-model="queryParams.licenseAddress"-->
<!--          placeholder="请输入营业执照注册地"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="企业地址" prop="enterpriseAddress">-->
<!--        <el-input-->
<!--          v-model="queryParams.enterpriseAddress"-->
<!--          placeholder="请输入企业地址"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="审核状态" prop="auditState">
        <el-select v-model="queryParams.auditState"  style="width: 100%;">
          <el-option
            v-for="item in option_auditState"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
<!--      <el-form-item label="审核时间" prop="auditTime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.auditTime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择审核时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="审核人姓名" prop="auditName">-->
<!--        <el-input-->
<!--          v-model="queryParams.auditName"-->
<!--          placeholder="请输入审核人姓名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="审核人工号" prop="auditNumber">-->
<!--        <el-input-->
<!--          v-model="queryParams.auditNumber"-->
<!--          placeholder="请输入审核人工号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="是否显示" prop="isShow">-->
<!--        <el-input-->
<!--          v-model="queryParams.isShow"-->
<!--          placeholder="请输入是否显示"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

<!--    <el-row :gutter="10" class="mb8">-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['project:demand:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['project:demand:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['project:demand:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['project:demand:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!--    </el-row>-->
    <el-table  :data="demandList"
               border
               :row-style="{height:'50px'}"
               :cell-style="{textAlign: 'center'}"
               :header-cell-style="{textAlign: 'center'}"  border style="width: 100%"
               v-loading="loading" @selection-change="handleSelectionChange">
<!--    <el-table v-loading="loading" :data="demandList" @selection-change="handleSelectionChange" height="750px">-->
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="需求名称" align="center" prop="resultName" />
      <el-table-column label="需求类别" align="center" prop="resultCategory">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cxcy_result_category" :value="scope.row.resultCategory"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="技术领域" align="center" prop="technology">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.cxcy_technology" :value="scope.row.technology"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="成果简介" align="center" prop="resultIntroduction" />-->
<!--      <el-table-column label="成果研究意义" align="center" prop="resultMeaning" />-->
<!--      <el-table-column label="法人姓名" align="center" prop="corporateName" />-->
<!--      <el-table-column label="企业营业执照" align="center" prop="businessLicense" />-->
<!--      <el-table-column label="营业执照注册地" align="center" prop="licenseAddress" />-->
<!--      <el-table-column label="企业地址" align="center" prop="enterpriseAddress" />-->
      <el-table-column label="审核状态" align="center" prop="auditState" >
      <template slot-scope="scope">
        <dict-tag :options="dict.type.cxcy_audit_status" :value="scope.row.auditState"/>
      </template>
      </el-table-column>
      <el-table-column label="审核时间" align="center" prop="auditTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.auditTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核人姓名" align="center" prop="auditName" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.auditState==='1'"
            @click="handleUpdate(scope.row)"
          >审核</el-button>
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.auditState==='2'||scope.row.auditState==='3'"
          >已审核</el-button>
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.auditState==='2'"
            @click="handleView(scope.row)"
          >详情</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['project:demand:remove']"-->
<!--          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>



    <!-- 添加或修改企业需求对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-container>
          <el-header>
            <el-divider content-position="left">
              <p style="color: #00afff; font-size: 20px;">基本信息</p>
            </el-divider>
          </el-header>
          <el-main>
            <el-row>
              <el-col :span="12">
                <el-form-item label="需求人姓名" prop="firstName">
                  <el-input v-model="form.firstName" disabled="true"   style="width: 100%"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="法人姓名" prop="corporateName">
                  <el-input v-model="form.corporateName" disabled="true"   style="width: 100%"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="企业名称" prop="enterpriseName">
                  <el-input v-model="form.enterpriseName" disabled="true"   style="width: 100%"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="企业地址" prop="enterpriseAddress" >
                  <el-input v-model="form.enterpriseAddress" disabled="true" style="width: 100%" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="创新点" prop="innovationPoint">
                  <el-input v-model="form.innovationPoint" type="textarea" placeholder="请输入审核意见" :rows="10" resize="none"/>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="成果研究意义" prop="resultMeaning">
                  <el-input v-model="form.resultMeaning" type="textarea" placeholder="请输入审核意见" :rows="10" resize="none"/>
                </el-form-item>
              </el-col><el-col :span="24">
              <el-form-item label="成果简介" prop="resultIntroduction">
                <el-input v-model="form.resultIntroduction" type="textarea" placeholder="请输入审核意见" :rows="10" resize="none"/>
              </el-form-item>
            </el-col>

<!--              <el-col :span="12">-->
<!--                <el-form-item label="企业地址" prop="enterpriseAddress" >-->
<!--                  <el-input v-model="form.enterpriseAddress" disabled="true" style="width: 100%" />-->
<!--                </el-form-item>-->
<!--              </el-col>-->
            </el-row>
          </el-main>
        </el-container>
        <el-container>
          <el-header>
            <el-divider content-position="left">
              <p style="color: #00afff; font-size: 20px;">审核信息</p>
            </el-divider>
          </el-header>
          <el-main>
            <el-row>
              <el-col :span="12">
                <el-form-item label="审核状态" prop="auditState">
                  <el-select v-model="form.auditState"  style="width: 100%;">
                    <el-option
                      v-for="item in option_auditState"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    ></el-option>
                  </el-select>
                  <!--<el-input v-model="form.auditState" placeholder="请输入审核状态"  style="width: 100%"/>-->
                </el-form-item>
              </el-col>
              <!--<el-col :span="12">
                <el-form-item label="审核时间" prop="auditTime">
                  <el-date-picker clearable
                                  disabled="true"
                                  v-model="form.auditTime"
                                  type="date"
                                  value-format="yyyy-MM-dd"
                                  style="width: 100%"
                                  placeholder="请选择审核时间">
                  </el-date-picker>
                </el-form-item>
              </el-col>-->
            </el-row>
            <el-row>
              <el-form-item label="审核意见" prop="note1">
                <el-input v-model="form.note1" type="textarea" placeholder="请输入审核意见" :rows="4" resize="none"/>
              </el-form-item>
            </el-row>
            <!--<el-row>
              <el-col :span="12">
                <el-form-item label="审核人姓名" prop="auditName">
                  <el-input v-model="form.auditName" placeholder="请输入审核人姓名"  style="width: 100%"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="审核人工号" prop="auditNumber">
                  <el-input v-model="form.auditNumber" placeholder="请输入审核人工号"  style="width: 100%"/>
                </el-form-item>
              </el-col>
            </el-row>-->
          </el-main>
        </el-container>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="aduitForm">确 定</el-button>
        <el-button @click="aduitCancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDemand, getDemand, delDemand, addDemand, updateDemand } from "@/api/module/lys/demand";


export default {
  name: "Demand",
  dicts: ['cxcy_result_category', 'cxcy_audit_status','cxcy_technology'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 企业需求表格数据
      demandList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        resultName: null,
        resultCategory: null,
        technology: null,
        resultIntroduction: null,
        innovationPoint: null,
        resultMeaning: null,
        firstName: null,
        firstId: null,
        firstPhone: null,
        firstIdnumber: null,
        enterpriseName: null,
        enterpriseNumber: null,
        corporateName: null,
        corporateEmail: null,
        corporatePhone: null,
        corporateNumber: null,
        businessLicense: null,
        licenseAddress: null,
        enterpriseAddress: null,
        auditState: null,
        auditTime: null,
        auditName: null,
        auditNumber: null,
        isShow: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      },
      option_auditState: [
        {
          value: '1',
          label: '待审核'},
        {
        value: '2',
        label: '通过'},
        {
        value: '3',
        label: '不通过'}],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询企业需求列表 */
    getList() {
      this.loading = true;
      listDemand(this.queryParams).then(response => {
        this.demandList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        resultName: null,
        resultCategory: null,
        technology: null,
        resultIntroduction: null,
        innovationPoint: null,
        resultMeaning: null,
        firstName: null,
        firstId: null,
        firstPhone: null,
        firstIdnumber: null,
        enterpriseName: null,
        enterpriseNumber: null,
        corporateName: null,
        corporateEmail: null,
        corporatePhone: null,
        corporateNumber: null,
        businessLicense: null,
        licenseAddress: null,
        enterpriseAddress: null,
        auditState: null,
        auditTime: null,
        auditName: null,
        auditNumber: null,
        isShow: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加企业需求";
    },
    // /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset();
    //   const id = row.id || this.ids
    //   getDemand(id).then(response => {
    //     this.form = response.data;
    //     this.open = true;
    //     this.title = "修改企业需求";
    //   });
    // },
    /** 审核按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDemand(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "审核企业需求申请";
      });
    },
    /** 审核提交按钮 */
    aduitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDemand(this.form).then(response => {
              this.$modal.msgSuccess("审核成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 审核取消按钮 */
    aduitCancel() {
      this.open = false;
      this.reset();
    },
    /** 详细按钮操作 */
    handleView(row) {
      const id = row.id || this.ids
      this.$router.push({ path:"/demo/detail", query: {id}});
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDemand(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDemand(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除企业需求编号为"' + ids + '"的数据项？').then(function() {
        return delDemand(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('project/demand/export', {
        ...this.queryParams
      }, `demand_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
